//
//  Personal.m
//  HYHOME
//
//  Created by cjy on 16/2/29.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "Personal.h"
#import "ZCViewController.h"
#import "DKNightVersion.h"

#import "SetUp.h"
#import "ME.h"
#import "Like.h"

@interface Personal ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,assign) BOOL loginState;

@property (nonatomic,retain)UITableView *tableView;
@property (nonatomic,retain)NSMutableArray *arr;
@property (nonatomic,retain)NSMutableArray *arrI;
@property (nonatomic,retain)UIButton *button;

@property (nonatomic,retain)UIImageView *me;
@property (nonatomic,retain)UIButton *button3;
@end

@implementation Personal

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"个人中心";
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"shezhi"] style:UIBarButtonItemStylePlain target:self action:@selector(next)];
    [self handle];
    [self  createtableView];
    
    [self viewWillAppear:YES];

}
- (void)next{
    
    
    SetUp *set = [[SetUp alloc]init];
    
    
    [self.navigationController pushViewController:set animated:YES];


}


- (void)handle{


    self.arr = @[@"收藏",@"联系客服"].mutableCopy;
    self.arrI = @[@"asd",@"lianxi"].mutableCopy;



}

- (void)createtableView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    [_tableView release];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    self.tableView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pool"];

    self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
    

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -200, [UIScreen mainScreen].bounds.size.width, 200)];

    imageView.image = [UIImage imageNamed:@"b9bca43dfedf03447dc1cb13b1ed1a19.jpg"];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.tag = 101;
    

    [self.tableView addSubview:imageView];
    imageView.userInteractionEnabled = YES;
    
    
    
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:1];
        UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithFrame:CGRectMake(0, -200, self.view.frame.size.width, 200)];
        visualView.effect = blur;
        visualView.tag = 102;

        [self.tableView addSubview:visualView];
        [visualView release];
    
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    
    
      self.button .frame = CGRectMake(0, -100 , self.view.frame.size.width/2 +20, 50);
    [ self.button  setTintColor:[UIColor whiteColor]];
    
     self.button .titleLabel.font = [UIFont systemFontOfSize:20];
    
    [self.tableView addSubview: self.button ];
    
    
    [ self.button  addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    button2.titleLabel.font = [UIFont systemFontOfSize:20];

    
    button2.frame = CGRectMake(170, -100, self.view.frame.size.width / 2 +20, 50);
    [button2 setTintColor:[UIColor whiteColor]];
    
    [button2 setTitle:@"注 册" forState:UIControlStateNormal];
    [self.tableView addSubview:button2];
    
    
    
    [button2 addTarget:self action:@selector(button2:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.button3 = [[UIButton alloc] initWithFrame:CGRectMake(imageView.center.x - 35, imageView.center.y - 50, 70, 70)];
    
    
    self.button3.layer.cornerRadius = 35;
    [self.button3 setImage:[UIImage imageNamed:@"dl"] forState:UIControlStateNormal];
//    self.button3.layer.cornerRadius = 40;

    [self.tableView addSubview:self.button3];
}

- (void)button2:(UIButton *)button2{


    ZCViewController *zc = [[ZCViewController alloc]init];
    
    [self.navigationController pushViewController:zc animated:YES];


}


- (void)button:(UIButton *)button{

        if (_loginState) {
            //注销
            //初始化弹窗
            
         
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否注销" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *defaultaction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
                NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                [user setBool:NO forKey:@"loginState"];
                //设置登录状态
                [self viewWillAppear:YES];
            }];
            
            
            [alert addAction:defaultaction];
            [self presentViewController:alert animated:YES completion:nil];
            
        
        }else{
            //登录
            ME *login = [[ME alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
            //模态显示
            
            [self.navigationController presentViewController:nav animated:YES completion:nil];
        }
    }


- (void)viewWillAppear:(BOOL)animated{
        //获取登录状态
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString *str = nil;
    
        self.loginState = [user boolForKey:@"loginState"];
        NSLog(@"self.loginState%d", self.loginState);
        if (self.loginState == YES) {
            NSLog(@"zx");
            str = @"注 销";
        }else{
            NSLog(@"dl");
            str = @"登 录";
        }
    [ self.button setTitle:str forState:UIControlStateNormal];
    }
    

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.tableView endEditing:YES];
}


/** 背景照片滑动 */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint point = scrollView.contentOffset;
    if (point.y < -200) {
        CGRect rect = [self.tableView viewWithTag:101].frame;
        rect.origin.y = point.y;
        rect.size.height = -point.y;
        [self.tableView viewWithTag:101].frame = rect;
        CGRect rect2 = [self.tableView viewWithTag:102].frame;
        rect2.origin.y = point.y;
        rect2.size.height = -point.y;
        [self.tableView viewWithTag:102].frame = rect2;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.arr.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    
  
    cell.imageView.image = [UIImage imageNamed:[self.arrI objectAtIndex:indexPath.row]];
    
    cell.textLabel.text = [self.arr objectAtIndex:indexPath.row];
    
    cell.textLabel.dk_textColorPicker = DKColorWithRGB(0x343434, 0xb8b8b8);

    cell.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);

    return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


    if(indexPath.row == 0){
    
        [self like];
    
    }else{
        
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"电话" message:@"400-690-0288" preferredStyle:UIAlertControllerStyleAlert];
            
            
            UIAlertAction *defaultaction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            }];
            
            
            [alert addAction:defaultaction];
            [self presentViewController:alert animated:YES completion:nil];

    
    }




}



- (void)like{
    if (_loginState) {
        Like *activity = [[Like alloc] init];
        //设置push隐藏tabbar
        activity.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:activity animated:YES];
    }else{
        //登录
        ME *login = [[ME alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
        //模态显示
        [self.navigationController presentViewController:nav animated:YES completion:nil];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
